/************************
 * 功能：消抖滤波
 * 作者：张亚辉
 * email：huiaove@126.com
 * 描述：消抖滤波
 * Data：2023/10/28
 * 地点：tianjin
 * *********************/
#include "GlitchFilter.h"


/// @brief 
/// @param filter 
/// @param value 
/// @param time 
/// @return 
uint8_t GlitchFilter_Value(Glitch_Filter_t *filter,uint32_t value,uint8_t time)
{
	if(value!=filter->last_value)
	{
		filter->time=0;
		filter->last_value=value;
	}
	else
	{
		filter->time+=time;
		if(filter->time>=filter->filter_time)
	  {
			filter->time=filter->filter_time;
			filter->out_value=value;
	  }
	}
	return filter->out_value;
}
//初始化消抖滤波器
uint8_t Register_GlitchFilter(Glitch_Filter_t *filter,uint16_t filter_time)
{
	filter->filter_time=filter_time;
	filter->out_value=0;
	filter->last_value=0;
	filter->time=0;
}